package com.sgb.kjwl.view.ui.fragment.enterprise;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.databinding.DataBindingUtil;
import androidx.fragment.app.Fragment;

import com.google.android.material.tabs.TabLayout;
import com.sgb.kjwl.AppLazyFragment;
import com.sgb.kjwl.R;
import com.sgb.kjwl.callback.OnTabSelectedListener;
import com.sgb.kjwl.databinding.FragmentPrMakeOverBinding;
import com.sgb.kjwl.view.ui.adapter.CommPagerAdapter3;

import java.util.ArrayList;

/**
 * 搜索界面大厅fragment
 */
public class PrMakeOverFragment extends AppLazyFragment {

    private FragmentPrMakeOverBinding mBinding;
    private int mIndex;

    public static PrMakeOverFragment newInstance() {
        PrMakeOverFragment fragment = new PrMakeOverFragment();
        Bundle bundle = new Bundle();
        fragment.setArguments(bundle);
        return fragment;
    }

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        mBinding = DataBindingUtil.inflate(inflater, R.layout.fragment_pr_make_over, container, false);
        return mBinding.getRoot();
    }

    @Override
    protected void onLazyLoad() {
    }

    @Override
    protected void initView() {
        mBinding.tabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
            @Override
            public void onTabSelected(TabLayout.Tab tab) {
                LinearLayout linearLayout = (LinearLayout) LayoutInflater.from(getActivity()).inflate(R.layout.item_lin_2, null);
                TextView selectTextView = linearLayout.findViewById(R.id.tab_item_textview);
                selectTextView.setText(tab.getText());
                tab.setCustomView(linearLayout);
            }

            @Override
            public void onTabUnselected(TabLayout.Tab tab) {
                tab.setCustomView(null);
            }

            @Override
            public void onTabReselected(TabLayout.Tab tab) {

            }
        });
        initTab(new String[]{"商标", "版权", "专利"});
    }


    private void initTab(String[] titls) {
        String categoryMark = null, categoryPatent = null, categoryCopyright = null, categoryCompany = null, categoryService = null, categoryProperty = null;
        ArrayList<Fragment> mList = new ArrayList<>();
        mList.add(IntellpropFragment.newInstance(0, categoryMark));
        mList.add(IntellpropFragment.newInstance(1, categoryPatent));
        mList.add(IntellpropFragment.newInstance(2, categoryCopyright));
        mBinding.vpMakeOver.setAdapter(new CommPagerAdapter3(getChildFragmentManager(), mList, titls));
        mBinding.vpMakeOver.setOffscreenPageLimit(titls.length);
        mBinding.tabLayout.setupWithViewPager(mBinding.vpMakeOver);
        mBinding.tabLayout.addOnTabSelectedListener(new OnTabSelectedListener() {
            @Override
            public void onTabSelected(TabLayout.Tab tab) {
                mIndex = tab.getPosition();
            }
        });
        mBinding.tabLayout.getTabAt(0).select();
        mBinding.vpMakeOver.setCurrentItem(0);
    }

}